﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using intelliPaper.Model;
using intelliSys.Management.Automation.Profiler.Properties;
namespace intelliSys.Management.Automation.Profiler
{
    class SystemStatistics
    {
        public string Count
        {
            get;
            set;
        }
        public string CategoryName
        {
            get;
            set;
        }
        public string Rate
        {
            get;
            set;
        }
        public string Suggestion
        {
            get;
            set;
        }
        static List<SystemStatistics> stats = null;
        public static IEnumerable<SystemStatistics> GetStatisticsCollection()
        {
            if (stats == null)
                stats = new List<SystemStatistics>();
            else
                return stats;
            if (DataRepository.Questions.Count != 0)
            {
                SystemStatistics ss1 = new SystemStatistics()
                {
                    Count = DataRepository.Questions.Count.ToString(),
                    CategoryName = "question information",
                    Rate = "average error rate" + DataRepository.Questions.Average<Question>(o =>
                        {
                            return o.NumericSummary;
                        }),
                    Suggestion = "#of error% larger than " + Settings.Default.PercentageHighlight + ": " + DataRepository.Questions.Where<Question>(o =>
                        {
                            return o.NumericSummary >= (int)Settings.Default.PercentageHighlight;
                        }).Count()
                };
                stats.Add(ss1);
            }
            if (DataRepository.KnowledgePoints.Count != 0)
            {
                SystemStatistics ss2 = new SystemStatistics()
                {
                    Count = DataRepository.KnowledgePoints.Count.ToString(),
                    CategoryName = "knowledgepoint information",
                    Rate = "average error rate" + DataRepository.KnowledgePoints.Average<KnowledgePoint>(o =>
                        {
                            return DataRepository.CalculateErrorRate(o);
                        }),
                    Suggestion = "#of error% larger than " + Settings.Default.PercentageHighlight + ": " + DataRepository.KnowledgePoints.Where<KnowledgePoint>(o =>
                        {
                            return o.NumericSummary >= (int)Settings.Default.PercentageHighlight;
                        }).Count()
                };
                stats.Add(ss2);
            }
            if (DataRepository.Papers.Count != 0)
            {
                SystemStatistics ss3 = new SystemStatistics()
                {
                    Count = DataRepository.Papers.Count.ToString(),
                    CategoryName = "paper information",
                    Rate = "average error rate" + DataRepository.Papers.Average<Paper>(o =>
                        {
                            return DataRepository.CalculateErrorRate(o);
                        }),
                    Suggestion = "#of error% larger than " + Settings.Default.PercentageHighlight + ": " + DataRepository.KnowledgePoints.Where<KnowledgePoint>(o =>
                         {
                             return o.NumericSummary >= (int)Settings.Default.PercentageHighlight;
                         }).Count()
                };
                stats.Add(ss3);
            }
            return stats;
        }
    }
    enum StatisticsEnabledCriteria
    {
        DBSIZE,
        QUESTION,
        PAPER,
        KNOWLEDGEPOINT
    }
}
